﻿//02.Write a program to convert binary numbers to their decimal representation.

using System;
using System.Linq;

namespace BinaryToDecimal
{
    class BinaryToDecimal
    {
        static void Main()
        {
            Console.Write("Please enter a binary number: ");
            string num = Console.ReadLine();
            int number = int.Parse(num);

            int[] numbers = new int[num.Length];
            
            for (int i = 0; i < num.Length; i++)
            {
                numbers[i] = int.Parse(num[i].ToString());
            }

            double[] calcNumbers = new double[numbers.Length];
            int sum = 0;

            int j = numbers.Length - 1;
            for (int i = 0; i < numbers.Length; i++)
            {
                sum += (int) (numbers[i] * (Math.Pow(2,j)));
                j--;
            }
            Console.WriteLine("Binary value = {0}, decimal value = {1}.", num, sum);
        }
    }
}
